package com.example.com.common.app;

import com.example.com.common.utils.ToastUtil;

/**
 * Created by ChenYiYao on 2018/2/1.
 */

public abstract class BViewActivity<Presenter extends BaseContract.Presenter>
        extends BaseActivity implements BaseContract.View<Presenter> {
    protected Presenter mPresenter;

    @Override
    protected void initBefore() {
        super.initBefore();
        initPresenter();
    }


    /**
     * 初始化Presenter
     *
     * @return Presenter
     */
    protected abstract Presenter initPresenter();

    @Override
    protected void initWidget() {
        super.initWidget();

    }

    @Override
    protected void initData() {
        super.initData();
        if (mPresenter != null) {
            mPresenter.start();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mPresenter != null) {
            mPresenter.destroy();
        }
    }

    @Override
    public void showError(String str) {
        ToastUtil.showToastLong(getApplicationContext(), str);
    }


    @Override
    public void showLoading(String str) {
        showProgressDialog(str);
    }

    @Override
    public void showLoading(String str, boolean flag) {
        showProgressDialog(str, flag);
    }

    @Override
    public void dimissLoading() {
        dismissProgressDialog();
    }

    @Override
    public void showSnackBarWarning(String str) {
        //空实现
    }

    @Override
    public void setPresenter(Presenter presenter) {
        // View中赋值Presenter
        mPresenter = presenter;
    }
}
